#!/usr/bin/env python

import webapp2
from google.appengine.api import users
from webapp2_extras.appengine.users import *
from models.models import *
import random

# NSW ART
#
bles = [
    {
        'name': 'Print - 75',
        'ble_android': 'D0:39:72:F4:06:75',
        'ble_ios': '7D264F7D-4DD1-5C00-2619-DB8C40B47A30'
    }, {
        'name': 'Archibald - 1E',
        'ble_android': 'D0:39:72:F4:0E:1E',
        'ble_ios': '35C2CE80-A0B5-EAD6-EAD8-45400102D086'
    }, {
        'name': 'Australian Contemporary Paintings - 09',
        'ble_android': 'D0:39:72:F4:0B:09',
        'ble_ios': 'DA4BD74B-7BB0-5D36-740C-2509EF6FF879'
    }
]

captions_ = [
    ["Federico Barocci, The Annunciation, circa 1584, print"],
    ["Eugene Delacroix, Lion of Atlas, 1829, print"]
], [
    ["Vincent Fantauzzo, All that's good in me, 2014, oil on linen"],
    ["Fiona Lowry, Penelope Seidler, 2014, acrylic on canvas"]
], [
    ["Stephen Bush, Ericifolia, 2004, painting"],
    ["Louise Hearman, Untitled #1304, 2009, painting"]
]

images = [
    [
        ["Andro-Croupier", "art-sections/nsw-art/Print_75/Federico.jpg"],
        ["Tom's fancy hat", "art-sections/nsw-art/Print_75/lion.jpg"]
    ], [
        ["The greens", "art-sections/nsw-art/Archibald_1E/Fantauzzo.jpg"],
        ["Toys and more toys", "art-sections/nsw-art/Archibald_1E/Fiona_Lowry.jpg"]
    ], [
        ["Reds Indoor - Range North", "art-sections/nsw-art/Australian_Contemporary_Paintings_09/Stephen_Bush.jpg"],
        ["Orange Sauvignon Blanc", "art-sections/nsw-art/Australian_Contemporary_Paintings_09/Louise_Hearman.jpg"],
    ]
]



# google creative lab

# bles = [
#     {
#         'name': 'CL - Wild Holiday Party - 75',
#         'ble_android': 'D0:39:72:F4:06:75',
#         'ble_ios': '7D264F7D-4DD1-5C00-2619-DB8C40B47A30'
#     }, {
#         'name': 'CL - Toys - 1E',
#         'ble_android': 'D0:39:72:F4:0E:1E',
#         'ble_ios': '35C2CE80-A0B5-EAD6-EAD8-45400102D086'
#     }, {
#         'name': 'CL - Foo Wine and Good Coffee - 09',
#         'ble_android': 'D0:39:72:F4:0B:09',
#         'ble_ios': 'DA4BD74B-7BB0-5D36-740C-2509EF6FF879'
#     }
# ]

# captions_ = [
#     ["Andro-Croupier"],
#     ["Tom's fancy hat"],
#     ["Best friend of Jude"],
#     ["685 Holiday Party"],
#     ["Not grumpy Crocodile"]
# ], [
#     ["The greens"],
#     ["Toys and more toys"],
#     ["Mess"],
#     ["Developer Cube"],
#     ["Green Pig in a mug"],
#     ["Hommer crew"]
# ], [
#     ["Reds Indoor - Range North"],
#     ["Orange Sauvignon Blanc"],
#     ["goto/bar.foo"],
#     ["Semi-Permanent / Cube"],
#     ["Nice Grumpy Strange Books"],
#     ["Best Coffee Lab spot"]
# ]

# images = [
#     [
#         ["Andro-Croupier", "art-sections/creative-lab/75/001.jpg"],
#         ["Tom's fancy hat", "art-sections/creative-lab/75/002.jpg"],
#         ["Best friend of Jude", "art-sections/creative-lab/75/003.jpg"],
#         ["685 Holiday Party", "art-sections/creative-lab/75/004.jpg"],
#         ["Not grumpy Crocodile", "art-sections/creative-lab/75/005.jpg"]
#     ], [
#         ["The greens", "art-sections/creative-lab/1E/001.jpg"],
#         ["Toys and more toys", "art-sections/creative-lab/1E/002.jpg"],
#         ["Mess", "art-sections/creative-lab/1E/003.jpg"],
#         ["Developer Cube", "art-sections/creative-lab/1E/004.jpg"],
#         ["Green Pig in a mug", "art-sections/creative-lab/1E/005.jpg"],
#         ["Hommer crew", "art-sections/creative-lab/1E/006.jpg"]
#     ], [
#         ["Reds Indoor - Range North", "art-sections/creative-lab/09/001.jpg"],
#         ["Orange Sauvignon Blanc", "art-sections/creative-lab/09/002.jpg"],
#         ["goto/bar.foo", "art-sections/creative-lab/09/003.jpg"],
#         ["Semi-Permanent / Cube", "art-sections/creative-lab/09/004.jpg"],
#         ["Nice Grumpy Strange Books", "art-sections/creative-lab/09/005.jpg"],
#         ["Best Coffee Lab spot", "art-sections/creative-lab/09/006.jpg"]
#     ]
# ]




# grumpy room
# bles = [
#     {
#         'name': 'GS - Foyer #1163 - 75',
#         'ble_android': 'D0:39:72:F4:06:75',
#         'ble_ios': '7D264F7D-4DD1-5C00-2619-DB8C40B47A30'
#     }, {
#         'name': 'GS - Main Room - #1164 - 1E',
#         'ble_android': 'D0:39:72:F4:0E:1E',
#         'ble_ios': '35C2CE80-A0B5-EAD6-EAD8-45400102D086'
#     }, {
#         'name': 'GS - Sculpture - #1165 - 09',
#         'ble_android': 'D0:39:72:F4:0B:09',
#         'ble_ios': 'DA4BD74B-7BB0-5D36-740C-2509EF6FF879'
#     }
# ]
# images = [
#     [
#         ["13th_century_stove","art-sections/foyer/13th_century_stove.jpg"],
#         ["hillbilly_roo","art-sections/foyer/hillbilly_roo.jpg"],
#         ["the_cube","art-sections/foyer/the_cube.jpg"],
#         ["pinocchios_mask","art-sections/foyer/pinocchios_mask.jpg"],
#     ], [
#         ["balls","art-sections/main_room/balls.jpg"],
#         ["chairs","art-sections/main_room/chairs.jpg"],
#         ["geometry","art-sections/main_room/geometry.jpg"],
#         ["plants","art-sections/main_room/plants.jpg"],
#         ["printbot","art-sections/main_room/printbot.jpg"],
#         ["reflections","art-sections/main_room/reflections.jpg"],
#         ["sailor_man","art-sections/main_room/sailor_man.jpg"],
#         ["weird_elf","art-sections/main_room/weird_elf.jpg"],
#     ],[
#         ["message","art-sections/sculpture_garden/message.jpg"],
#         ["hat","art-sections/sculpture_garden/hat.jpg"],
#         ["tape_stacked","art-sections/sculpture_garden/tape_stacked.jpg"],
#     ]
# ]

# images = [
#     [
#         ["aussix", "art-sections/auto-obsession/512/aussix.jpg"],
#         ["eaw", "art-sections/auto-obsession/512/eaw.jpg"],
#         ["ehholden", "art-sections/auto-obsession/512/ehholden.jpg"],
#         ["fjholden", "art-sections/auto-obsession/512/fjholden.jpg"],
#         ["minik", "art-sections/auto-obsession/512/minik.jpg"],
#         ["minx", "art-sections/auto-obsession/512/minx.jpg"],
#         ["model9k", "art-sections/auto-obsession/512/model9k.jpg"],
#         ["modeld", "art-sections/auto-obsession/512/modeld.jpg"],
#         ["regalvf", "art-sections/auto-obsession/512/regalvf.jpg"],
#         ["rolls", "art-sections/auto-obsession/512/rolls.jpg"],
#         ["simplex", "art-sections/auto-obsession/512/simplex.jpg"],
#         ["zeta3", "art-sections/auto-obsession/512/zeta3.jpg"]
#     ], [
#         ["43-838x1024", "art-sections/interface/512/43-838x1024.jpg"],
#         ["ipad", "art-sections/interface/512/ipad.jpg"],
#         ["IS-3881-0001", "art-sections/interface/512/IS-3881-0001.jpg"],
#         ["IS-4516-0005", "art-sections/interface/512/IS-4516-0005.jpg"],
#         ["IS-4564-0005", "art-sections/interface/512/IS-4564-0005.jpg"],
#         ["IS-4575-0012", "art-sections/interface/512/IS-4575-0012.jpg"],
#         ["IS-4652-0008", "art-sections/interface/512/IS-4652-0008.jpg"],
#         ["IS-5637-0009", "art-sections/interface/512/IS-5637-0009.jpg"],
#         ["IS-5907-0013", "art-sections/interface/512/IS-5907-0013.jpg"],
#         ["IS-5908-0011", "art-sections/interface/512/IS-5908-0011.jpg"],
#         ["IS-5909-0003", "art-sections/interface/512/IS-5909-0003.jpg"],
#         ["IS-5909-0007", "art-sections/interface/512/IS-5909-0007.jpg"],
#         ["IS-5909-0013", "art-sections/interface/512/IS-5909-0013.jpg"],
#         ["IS-5911-00021", "art-sections/interface/512/IS-5911-00021.jpg"],
#         ["IS-5911-0004", "art-sections/interface/512/IS-5911-0004.jpg"],
#         ["IS-5915-0009", "art-sections/interface/512/IS-5915-0009.jpg"],
#         ["IS-5915-0020", "art-sections/interface/512/IS-5915-0020.jpg"],
#         ["kit1-1024x694", "art-sections/interface/512/kit1-1024x694.jpg"],
#         ["pglove", "art-sections/interface/512/pglove.jpg"]
#     ], [
#         ["Picture_0006-2-866x1024",
#             "art-sections/interface/512/Picture_0006-2-866x1024.jpg"],
#         ["Picture_0010-1024x863",
#             "art-sections/interface/512/Picture_0010-1024x863.jpg"],
#         ["9519007259_5646933a53_k",
#             "art-sections/love-lace/512/9519007259_5646933a53_k.jpg"],
#         ["9519012285_6377ae3120_k",
#             "art-sections/love-lace/512/9519012285_6377ae3120_k.jpg"],
#         ["9519021829_ad88f2ae45_k",
#             "art-sections/love-lace/512/9519021829_ad88f2ae45_k.jpg"],
#         ["9519023609_f21678abca_k",
#             "art-sections/love-lace/512/9519023609_f21678abca_k.jpg"],
#         ["9519034279_def6779dc3_k",
#             "art-sections/love-lace/512/9519034279_def6779dc3_k.jpg"],
#         ["9521781070_6ce8865e13_k",
#             "art-sections/love-lace/512/9521781070_6ce8865e13_k.jpg"],
#         ["9521814662_378e5a2bf1_k",
#             "art-sections/love-lace/512/9521814662_378e5a2bf1_k.jpg"],
#         ["9521816520_4be6d2b8c4_k",
#             "art-sections/love-lace/512/9521816520_4be6d2b8c4_k.jpg"],
#         ["9521817956_802ca31ed0_k",
#             "art-sections/love-lace/512/9521817956_802ca31ed0_k.jpg"],
#         ["9521821982_1927d04613_k",
#             "art-sections/love-lace/512/9521821982_1927d04613_k.jpg"]
#     ]
# ]


class AddImagesHandler(webapp2.RequestHandler):
    @admin_required
    def get(self):
        user = users.get_current_user()

        # host = 'http://192.168.1.33:22080/'

        # sec = ArtSection(name="Section Two #01165")
        # sec.ble_android = 'D0:39:72:0B:09'
        # sec.ble_ios = '245D72225-8896-7D74-3D15-305CADB249DE'
        # sec.put()

        for i in range(len(bles)):
            sec = ArtSection(name=bles[i]['name'])
            sec.ble_android = bles[i]['ble_android']
            sec.ble_ios = bles[i]['ble_ios']
            sec.put()

            for j in range(len(images[i])):
                art = ArtPiece(
                    parent=sec.key,
                    title=images[i][j][0],
                    image_url=images[i][j][1])
                art.put()

                print 'added %s: %s' % (images[i][j][0], images[i][j][1])

                caption = Caption(
                    parent=art.key,
                    user=user,
                    text=captions_[i][j][0])
                caption.put()

                # for k in range(random.randint(1,4)):
                #     caption = Caption(
                #         parent=art.key,
                #         user=user,
                #         text='Another wonderful piece of Art! %s' % str(k))
                #     caption.put()
            print '---------\n\n'
        # for i in range(9):
        #     art = ArtPiece(
        #         parent=sec.key,
        #         title="picture",
        #         image_url="%sassets/images/cartoon-%s.jpg" % (host, str(i)))
        #     art.put()

        #     caption = Caption(
        #         parent=art.key,
        #         user=user,
        #         text='Another wonderful piece of Art! %s' % str(i))
        #     caption.put()

        self.response.out.write("succesfully added images")


class DeleteImagesHandler(webapp2.RequestHandler):
    def get(self):
        while Caption.query().count() > 0:
            print 'deleting Captions'
            captoin_keys = Caption.query().fetch(200, keys_only=True)
            ndb.delete_multi(captoin_keys)

        while ArtPiece.query().count() > 0:
            print 'deleting Art Pieces'
            artpiece_keys = ArtPiece.query().fetch(200, keys_only=True)
            ndb.delete_multi(artpiece_keys)

        while ArtSection.query().count() > 0:
            print 'deleting Art sections'
            artsection_keys = ArtSection.query().fetch(200, keys_only=True)
            ndb.delete_multi(artsection_keys)

        self.response.out.write('Delete complete')


class LogoutHandler(webapp2.RequestHandler):
    def get(self):
        url = users.create_logout_url('/')
        self.response.out.write('<a href="%s">logout</a>' % url)
